package spring.JUNIT.ANNOTATION.multibean;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class BeanInvoker {

	@Autowired
	private List<BeanInterface> list;

	@Autowired
	private Map<String, BeanInterface> map;

	@Autowired
	@Qualifier("beanImplTow")
	private BeanInterface beanInterface;

	public void asy() throws Exception, SecurityException {
		if (null != list && list.size() > 0) {
			for (BeanInterface beanInterface : list) {
				System.out.println(beanInterface.getClass().getSimpleName());

				if (beanInterface instanceof BeanImplTow) {
					Method aMethod = beanInterface.getClass()
							.getDeclaredMethod("say");
					aMethod.setAccessible(true);
					aMethod.invoke(beanInterface);
				}
			}

		} else {
			System.out.println("list is null");
		}

		if (null != map && map.size() > 0) {
			for (Map.Entry<String, BeanInterface> entry : map.entrySet()) {
				System.out.println(entry.getKey() + "     "
						+ entry.getValue().getClass().getName());
			}
		}

		System.out.println("____________________________________________");

		if (null != beanInterface) {
			System.out.println(beanInterface.getClass().getSimpleName());
		}

	}
}
